package com.thread.demo11;

import java.util.concurrent.locks.LockSupport;

public class JoinDemo2 {
	
	public static void main(String[] args) throws InterruptedException {
		Thread previous = Thread.currentThread();
		for(int i=1;i<10;i++){
			Thread t = new Thread(new Domino(previous),String.valueOf(i)+"sub");
			t.start();
			previous = t;
		}
//		LockSupport.park();
		Thread.sleep(5000);
		System.out.println(Thread.currentThread().getName()+"==");
	}
	
	static class Domino implements Runnable{
		private Thread thread;
		public Domino(Thread thread) {
			this.thread = thread;
		}
		@Override
		public void run() {
			try {
				//当前线程等待thread线程执行结束之后，join才会返回，才会开始执行当前线程join之后的方法
				thread.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+"==");
		}
	}

}
